<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="form.name" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="提交时间" width="236">
              <el-date-picker
                v-model="form.time"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="4" :offset="2"> -->
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <!-- <el-button type="primary" @click="handleExport">导出</el-button> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column
          fixed
          type="index"
          label="序号"
          width="50"
          align="center"
          :index="table_index"
        />
        <el-table-column prop="name" label="姓名" align="center" />
        <el-table-column prop="phone" label="手机号" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.phone | phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="employment_images" label="资格证/工作证" align="center">
          <template slot-scope="scope">
            <div>
              <div
                style="color: rgba(0, 153, 204); cursor:pointer"
                v-for="(item,index) in scope.row.employment_images.split(',')"
                :key="index"
                @click="openPic(item)"
              >资格证{{index+1}}</div>
              <!-- <a
                :href="item | imgUrlFn"
                v-for="(item,index) in scope.row.employment_images.split(',')"
                :key="index"
              >资格证{{index+1}}</a>-->
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="pass_images" label="出入通行证" align="center">
          <template slot-scope="scope">
            <div>
              <div
                style="color: rgba(0, 153, 204); cursor:pointer"
                v-for="(item,index) in scope.row.pass_images.split(',')"
                :key="index"
                @click="openPic1(item)"
              >通行证{{index+1}}</div>
              <!-- <a
                :href="item | imgUrlFn"
                v-for="(item,index) in scope.row.pass_images.split(',')"
                :key="index"
              >通行证{{index+1}}</a>-->
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="提交时间" align="center">
          <template slot-scope="scope">{{ scope.row.created_at | dates }}</template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <!-- 资格证图片弹窗 -->
    <!--  @open="openDia" -->
    <el-dialog title :visible.sync="dialogFormVisible" width="80%" @close="clear">
      <img :src="imgUrl | imgUrlFn" alt />
    </el-dialog>
    <!-- 通行证图片弹窗 -->
    <!--  @open="openDia1" -->
    <el-dialog title :visible.sync="dialogFormVisible1" width="80%" @close="clear1">
      <img :src="imgUrl2 | imgUrlFn" alt />
    </el-dialog>
  </div>
</template>
<script>
import { getList, activeExport } from "@/api/informationMange";
import commonFn from "@/utils/common";
export default {
  name: "informationList",
  data() {
    return {
      form: {
        name: "",
        phone: "",
        time: "",
        page: 1,
        pageSize: 10
      },
      tableData: [],
      // 分页
      page_sizes: [10, 30, 50, 100], // 每页显示个数
      page_totals: 0, // 总条目数,
      tableLoading: true,
      imgUrl: "",
      imgUrl2: "",
      dialogFormVisible: false,
      dialogFormVisible1: false,
      isShow: false
    };
  },
  filters: {
    // 图片域名地址
    imgUrlFn: function(e) {
      return localStorage.getItem("imgUrlPrefix") + e;
    },
    // 时间戳转化
    dates(e) {
      if (e != 0) {
        return new Date(Number(e) * 1000).format("yyyy-MM-dd hh:mm:ss");
      } else {
        return "";
      }
    }
  },
  created() {
    this.getList(this.form);
  },
  methods: {
    table_index(index) {
      return (this.form.page - 1) * this.form.pageSize + index + 1;
    },
    // 列表
    getList(e) {
      getList(e)
        .then(res => {
          if (res.data.code == 200) {
            // console.log(res.data);
            this.tableData = res.data.data;
            this.page_totals = res.data.page_totals;
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: "warning"
            });
          }
          this.tableLoading = false;
        })
        .catch(err => {
          this.errorStatus(err.msg);
          this.tableLoading = false;
        });
    },
    //   查询
    handleSearch() {
      this.form.page = 1;
      this.getList(this.form);
    },
    //   导出
    handleExport() {
      const listExport = { ...this.form };
      delete listExport.page;
      delete listExport.pageSize;
      activeExport(listExport)
        .then(res => {
          console.log("Res", res);
          commonFn.downFile("活动查询信息导出", res);
        })
        .catch(err => {
          this.errorStatus(err.msg);
        });
    },
    // 打开图片
    openPic(e) {
      this.imgUrl = e;
      this.dialogFormVisible = true;
    },
   
    // 通行证图片打开
    openPic1(e) {
      this.imgUrl2 = e;
      this.dialogFormVisible1 = true;
    },
    // openDia() {
    //   this.imgUrl = "";
    // },
    // openDia1(){
    //    this.imgUrl2 = '';
    // },
    // 资格证清空
    clear() {
      this.imgUrl = "";
      this.dialogFormVisible = false;
    },
    clear1() {
      this.imgUrl2 = "";
      this.dialogFormVisible1 = false;
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pagesize = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    // 弹窗组件
    eleMsg(txt, status) {
      this.$message({
        showClose: true,
        message: txt,
        type: status
      });
    },
    // 成功状态弹窗
    succStatus(txt, status) {
      this.eleMsg(txt, "success");
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.eleMsg(txt, "error");
    }
  }
};
</script>
<style scoped>
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
/* 分页样式 */
.pagesCon {
  margin-top: 20px;
  text-align: right;
}
a {
  display: block;
  color: rgba(0, 153, 204);
}
img {
  width: 100%;
  height: 100%;
}
</style>